//
//  NSArray+Safe.m
//  TestMethod
//
//  Created by js on 15/11/9.
//  Copyright © 2015年 js. All rights reserved.
//

#import "NSArray+LBSafe.h"
#import <objc/runtime.h>

@implementation NSArray (LBSafe)

+ (void)load{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        //NSArray
        Method method = class_getInstanceMethod(NSClassFromString(@"__NSArrayI"), @selector(objectAtIndex:));
        Method method2 = class_getInstanceMethod(NSClassFromString(@"__NSArrayI"), @selector(safeObjectAtIndex:));
        method_exchangeImplementations(method, method2);
    });
}

- (id)safeObjectAtIndex:(NSInteger)index{
    if (self.count > index) {
        return [self safeObjectAtIndex:index];
    }
    
    NSLog(@"数组越界");
    return nil;
}

- (id)objectForKey:(NSString *)index{
    return nil;
}


@end
